// ham them dau cham vao String tien

	public String ThanhTien(String sotien) {
		int leng = sotien.length();
		char mang[];
		mang = sotien.toCharArray();// chuyen chuoi thanh 1 mang ky tu
		if (leng == 4)
			return mang[0] + "." + mang[1] + "" + mang[2] + "" + mang[3]; // 1.000
		if (leng == 5)
			return mang[0] + "" + mang[1] + "." + mang[2] + "" + mang[3] + ""
					+ mang[4];// 10.000
		if (leng == 6)
			return mang[0] + "" + mang[1] + "" + mang[2] + "." + mang[3] + ""
					+ mang[4] + "" + mang[5]; // 100.000
		if (leng == 7)
			return mang[0] + "." + mang[1] + "" + mang[2] + "" + mang[3] + "."
					+ mang[4] + "" + mang[5] + "" + mang[6]; // 1.000.000
		if (leng == 8)
			return mang[0] + "" + mang[1] + "." + mang[2] + "" + mang[3] + ""
					+ mang[4] + "." + mang[5] + "" + mang[6] + "" + mang[7]; // 10.000.000
		if (leng == 9)
			return mang[0] + "" + mang[1] + "" + mang[2] + "." + mang[3] + ""
					+ mang[4] + "" + mang[5] + "." + mang[6] + "" + mang[7]
					+ "" + mang[8]; // 100.000.000
		if (leng == 10)
			return mang[0] + "." + mang[1] + "" + mang[2] + "" + mang[3] + "."
					+ mang[4] + "" + mang[5] + "" + mang[6] + "." + mang[7]
					+ "" + mang[8] + "" + mang[9];// 1.000.000.000
		if (leng == 11)
			return mang[0] + "" + mang[1] + "." + mang[2] + "" + mang[3] + ""
					+ mang[4] + "." + mang[5] + "" + mang[6] + "" + mang[7]
					+ "." + mang[8] + "" + mang[9] + "" + mang[10]; // 10.000.000.000
		if (leng == 12)
			return mang[0] + "" + mang[1] + "" + mang[2] + "." + mang[3] + ""
					+ mang[4] + "" + mang[5] + "." + mang[6] + "" + mang[7]
					+ "" + mang[8] + "." + mang[9] + "" + mang[10] + ""
					+ mang[11]; // 100.000.000.000
		if (leng == 13)
			return mang[0] + "." + mang[1] + "" + mang[2] + "" + mang[3] + "."
					+ mang[4] + "" + mang[5] + "" + mang[6] + "." + mang[7]
					+ "" + mang[8] + "" + mang[9] + "." + mang[10] + ""
					+ mang[11] + "" + mang[12]; // 1.000.000.000.000
		if (leng == 14)
			return mang[0] + "" + mang[1] + "." + mang[2] + "" + mang[3] + ""
					+ mang[4] + "." + mang[5] + "" + mang[6] + "" + mang[7]
					+ "." + mang[8] + "" + mang[9] + "" + mang[10] + "."
					+ mang[11] + "" + mang[12] + "" + mang[13]; // 10.000.000.000.000
		if (leng == 15)
			return mang[0] + "" + mang[1] + "" + mang[2] + "." + mang[3] + ""
					+ mang[4] + "" + mang[5] + "." + mang[6] + "" + mang[7]
					+ "" + mang[8] + "." + mang[9] + "" + mang[10] + ""
					+ mang[11] + "." + mang[12] + "" + mang[13] + "" + mang[14];// 100.000.000.000.000
		if (leng == 16)
			return mang[0] + "." + mang[1] + "" + mang[2] + "" + mang[3] + "."
					+ mang[4] + "" + mang[5] + "" + mang[6] + "." + mang[7]
					+ "" + mang[8] + "" + mang[9] + "." + mang[10] + ""
					+ mang[11] + "" + mang[12] + "." + mang[13] + "" + mang[14]
					+ "" + mang[15];// 1.000.000.000.000.000
		if (leng == 17)
			return mang[0] + "" + mang[1] + "." + mang[2] + "" + mang[3] + ""
					+ mang[4] + "." + mang[5] + "" + mang[6] + "" + mang[7]
					+ "." + mang[8] + "" + mang[9] + "" + mang[10] + "."
					+ mang[11] + "" + mang[12] + "" + mang[13] + "." + mang[14]
					+ "" + mang[15] + "" + mang[16]; // 10.000.000.000.000
		if (leng == 18)
			return mang[0] + "" + mang[1] + "" + mang[2] + "." + mang[3] + ""
					+ mang[4] + "" + mang[5] + "." + mang[6] + "" + mang[7]
					+ "" + mang[8] + "." + mang[9] + "" + mang[10] + ""
					+ mang[11] + "." + mang[12] + "" + mang[13] + "" + mang[14]
					+ "." + mang[15] + "" + mang[16] + "" + mang[17]; // 100.000.000.000.000
		else
			return sotien;
	}

	// cac ham xu ly va nhan ket qua tu server
	public int Dangnhap(String loaigiaodich, String stk, String mk,
			String bienrong) throws Exception {
		int ketqua = 0;
		out.println(loaigiaodich);
		out.flush();
		out.println(stk);
		out.flush();
		out.println(mk);
		out.flush();
		out.println(bienrong);
		out.flush();
		String kq = in.readLine();
		ketqua = Integer.parseInt(kq);
		name = in.readLine();
		System.out.println("Ten cua nguoi dang nhap nhan duoc tu server la:"
				+ name);
		return ketqua;
	}

	public void Xemsodu(String loaigiaodich, String stk, String bienrong1,
			String bienrong2) throws Exception {
		out.println(loaigiaodich);
		out.flush();
		out.println(stk);
		out.flush();
		out.println(bienrong1);
		out.flush();
		out.println(bienrong2);
		out.flush();
		String kq = in.readLine();
		tien = Integer.parseInt(kq);
		System.out.println("So tien nhan duoc tu server la:" + tien);
		LSodu.setText(stconlai + ThanhTien(tien.toString()) + " VND");

	}

	public int Nap(String loaigiaodich, String stk, Integer sotien,
			String bienrong) throws Exception {
		int ketqua = 0;
		out.println(loaigiaodich);
		out.flush();
		out.println(stk);
		out.flush();
		out.println(sotien);
		out.flush();
		out.println(bienrong);
		out.flush();
		String kq = in.readLine();
		ketqua = Integer.parseInt(kq);
		String t = in.readLine();
		tien = Integer.parseInt(t);
		if (ketqua == 1) {
			l1nap.setText(txtAccountNo.getText());// so tai khoan
			l2nap.setText(ThanhTien(sotien.toString()) + " VND");// so tien nap
			l3nap.setText(ThanhTien(tien.toString()) + " VND");// tong so tien
																// trong tai
																// khoan
			Integer tam = tien - 50000;
			l4nap.setText(ThanhTien(tam.toString()) + " VND");// so tien cho
																// phep duoc rut

		}
		return ketqua;

	}

	public int Rut(String loaigiaodich, String stk, Integer sotien,
			String bienrong) throws Exception {
		int ketqua = 0;
		out.println(loaigiaodich);
		out.flush();
		out.println(stk);
		out.flush();
		out.println(sotien);
		out.flush();
		out.println(bienrong);
		out.flush();
		String kq = in.readLine();
		ketqua = Integer.parseInt(kq);
		String tienserver = in.readLine();
		tien = Integer.parseInt(tienserver);
		if (ketqua == 1) {
			l1.setText(txtAccountNo.getText());// so tai khoan
			l2.setText(ThanhTien(sotien.toString()) + " VND");// so tien rut
			l3.setText(ThanhTien(tien.toString()) + " VND");// so tien con lai
															// trong tai khoan
			Integer tam = tien - 50000;
			l4.setText(ThanhTien(tam.toString()) + " VND");// so tien duoc phep
															// rut tiep

		}
		return ketqua;
	}

	public int Doimatkhau(String loaigiaodich, String stk, String mkmoi,
			String bienrong) throws Exception {
		int ketqua = 0;
		out.println(loaigiaodich);
		out.flush();
		out.println(stk);
		out.flush();
		out.println(mkmoi);
		out.flush();
		out.println(bienrong);
		out.flush();
		String kq = in.readLine();
		ketqua = Integer.parseInt(kq);
		return ketqua;
	}

	public int Chuyenkhoan(String loaigiaodich, String tkgui, String tknhan,
			Integer sotien) throws Exception {
		int ketqua = 0;
		out.println(loaigiaodich);
		out.flush();
		out.println(tkgui);
		out.flush();
		out.println(tknhan);
		out.flush();
		out.println(sotien);
		out.flush();
		String kq = in.readLine();
		ketqua = Integer.parseInt(kq);
		String t = in.readLine();
		tien = Integer.parseInt(t);
		if (ketqua == 1) {
			l5.setText(tkgui);// so tai khoan nguoi chuyen
			l6.setText(Sotkhoan.getText());// so tai khoan nguoi duoc chuyen
			l7.setText(ThanhTien(sotien.toString()) + " VND");// so tien chuyen
			l8.setText(ThanhTien(Long.toString(tien)) + " VND");// so tien con
																// trong tai
																// khoan
			Integer tam = tien - 50000;
			l9.setText(ThanhTien(Integer.toString(tam)) + " VND");// so du cho
																	// phep
		}

		return ketqua;

	}

	public int Kiemtratknhan(String loaigiaodich, String stk, String bienrong1,
			String bienrong2) throws Exception {
		int ketqua = 0;
		out.println(loaigiaodich);
		out.flush();
		out.println(stk);
		out.flush();
		out.println(bienrong1);
		out.flush();
		out.println(bienrong2);
		out.flush();
		String kq = in.readLine();
		ketqua = Integer.parseInt(kq);
		return ketqua;

	}

	// <-------------------------------------------------------------------------->
	// ket thuc cac ham
	// <---------------------------------------------------------------------------------------------------->

	// <----------------------------------------------------------------------------------------------------->
	// PHAN XU LY SU KIEN
	// <----------------------------------------------------------------------------------------------------->

	public void actionPerformed(ActionEvent ae) {

		// <------------------------------------------------------------------------------------------------------->
		// login

		if (ae.getSource() == btxoa) {
			txtAccountNo.setText("");
			txtPassword.setText("");
			txtAccountNo.requestFocus();

		}

		else if (ae.getSource() == btenter)

		{
			try {
				String tendangnhap = txtAccountNo.getText();
				String mk = txtPassword.getText();
				int thanhcong = Dangnhap("DangNhap", tendangnhap, mk, "null");
				if (thanhcong == 0) {
					JOptionPane.showMessageDialog(this, loi1, "Thong bao",
							JOptionPane.ERROR_MESSAGE);// tai khoan hoac mat
														// khau khong hop le
					txtAccountNo.setText("");
					txtPassword.setText("");
					txtAccountNo.requestFocus();

				}

				else {
					nowAcc = txtAccountNo.getText();
					nowPass = txtPassword.getText();
					LName.setText(" WELCOME " + name.toUpperCase());
				   LName.setFont(new Font("Courier New", Font.BOLD,25));
				   LName.setForeground(Color.red);
					LName2.setText(" WELCOME " + name.toUpperCase());
					LName2.setFont(new Font("Courier New", Font.BOLD,25));
					   LName2.setForeground(Color.red);
					LName3.setText(" WELCOME " + name.toUpperCase());
					LName3.setFont(new Font("Courier New", Font.BOLD,25));
					   LName3.setForeground(Color.red);
					LName2nap.setText(" WELCOME " + name.toUpperCase());
					LName2nap.setFont(new Font("Courier New", Font.BOLD,25));
					   LName2nap.setForeground(Color.red);
					LName3nap.setText(" WELCOME " + name.toUpperCase());
					LName3nap.setFont(new Font("Courier New", Font.BOLD,25));
					   LName3nap.setForeground(Color.red);
					twoPane.setBottomComponent(Pmain);
				}

			} catch (Exception e) {
				System.out.println("loi gi day" + e);
			}

		}
		// <-------------------------------------------------------------------------------------------------->
